package com.example.activelifecycletest.fruit;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.activelifecycletest.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 水果活动类
 * @author zhangding
 * @date 2022年4月19日23:12:29
 */
public class FruitActivity extends AppCompatActivity {
    private List<Fruit> fruitList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recycler_view_test);
        initFruits();
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        FruitAdapter adapter = new FruitAdapter(fruitList);
        recyclerView.setAdapter(adapter);
    }
    private void initFruits(){
        for(int i = 0; i<2; i++){
            Fruit apple = new Fruit("APPLE",1);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);
            fruitList.add(apple);


        }
    }
}
